<?php
	class TypeAction extends BaseAction {
		public function addtype(){
			if(!$this->isPost()){
				$this->display();
			}else{
				$data['t_name'] = $_POST['x_type'];
				$result = M("type")->data($data)->add();
				if($result){
					echo "添加成功";
				}else{
					echo "添加失败";
				}
			}
		}
		
		public function listtype(){
			if(!$this->isPost()){
				$result = M("type")->select();
				$this->assign("type",$result);
				$this->display();
			}else{
				if($_POST['fun']=='del'){
					$t_id = $_POST['t_id'];
					$result = M("type")->where("t_id = $t_id")->delete();
					if($result){
						echo 1;
					}else{
						echo 0;
					}
				}elseif($_POST['fun']=='updates'){
					$t_id = $_POST['t_id'];
					$result = M("type")->where("t_id=$t_id")->select();
					$this->assign("type",$result);
					$this->display("uptype");
				}elseif($_POST['fun']=='up'){
					$t_id = $_POST['t_id'];
					$data['t_name']=$_POST['t_name'];
					$result = M("type")->where("t_id=$t_id")->save($data);

					if($result){
						echo "修改成功";
					}else{
						echo  "修改失败";
					}

				}
			}	
		}

		public function addrent(){
			if(!$this->isPost()){
				$this->display();
			}else{
				$data['r_name'] = $_POST['r_name'];
				$result = M("rent")->data($data)->add();
				if($result){
					echo "添加成功";
				}else{
					echo  "添加失败";
				}
			}
		
		}

		public function listrent(){
			if(!$this->isPost()){
				$result = M("rent")->select();
				$this->assign("rent",$result);
				$this->display();
			}else{
				if($_POST['fun']=='del'){
					$r_id = $_POST['r_id'];
					$result = M("rent")->where("r_id = $r_id")->delete();
					if($result){
						echo 1;
					}else{
						echo 0;
					}
				}elseif($_POST['fun']=='updates'){
					$r_id = $_POST['r_id'];
					$result = M("rent")->where("r_id=$r_id")->select();
					$this->assign("rent",$result);
					$this->display("uprent");
				}elseif($_POST['fun']=='up'){
					$r_id = $_POST['r_id'];
					$data['r_name']=$_POST['r_name'];
					$result = M("rent")->where("r_id=$r_id")->save($data);

					if($result){
						echo "修改成功";
					}else{
						echo  "修改失败";
					}

				}
			}	
		}

	}

?>